<?php
class NoBusinessBase_Utility_SimpleEncodeDecode
{
   protected $mKey  = null;

   public  function __construct($key)
   {
      $this->mKey = $key;
   }

   public function __clone()
   {
      trigger_error('Clone is not allowed.', E_USER_ERROR);
   }

   public function __wakeup()
   {
      trigger_error('Unserializing is not allowed.', E_USER_ERROR);
   }


   public function __destruct()
   {
   }

/************************************************************************/
/* Interface                                                            */
/************************************************************************/

   public function encode($string)
   {
      $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($this->mKey), $string, MCRYPT_MODE_CBC, md5(md5($this->mKey))));
 
      return $encrypted;
   }

   public function decode($encrypted)
   {
      $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($this->mKey), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($this->mKey))), "\0");
      
      return $decrypted;
   }

}
